<?php

namespace App\Http\Validate\Cruise;

use App\Http\Validate\AbstractBaseValidate;
use App\Models\Cruise\CruiseCheckSelfDetailModel;
use App\Models\Cruise\CruiseOrderModel;
use App\Models\Cruise\CruiseTemplateModel;
use App\Models\Shop\ShopModel;
use Illuminate\Support\MessageBag;
use Illuminate\Validation\Rule;
use Illuminate\Validation\ValidationException;
use Psr\Container\ContainerExceptionInterface;
use Psr\Container\NotFoundExceptionInterface;

class CruiseCheckValidate extends AbstractBaseValidate
{
    function getRules(): array
    {
        // TODO: Implement getRules() method.
        return [];
    }

    function getAttributes(): array
    {
        // TODO: Implement getAttributes() method.
        return [];
    }

    function registerValidateRules(): void
    {
        // TODO: Implement registerValidateRules() method.
    }

    function getMessages(): array
    {
        // TODO: Implement getMessages() method.
        return [];
    }

    /**
     * 模板类型校验
     *
     * @param array $params
     * @return MessageBag|object
     * @throws ValidationException
     * @throws ContainerExceptionInterface
     * @throws NotFoundExceptionInterface
     */
    public static function systemTemplateValidate(array $params)
    {
        return self::getInstance()->validate(
            ["templateType"],
            $params,
            [
                "templateType" => self::intInValidateBuild(true, CruiseTemplateModel::TYPE_TEXT)
            ]
        );
    }

    /**
     * 模板类型校验
     *
     * @param array $params
     * @return MessageBag|object
     * @throws ValidationException
     * @throws ContainerExceptionInterface
     * @throws NotFoundExceptionInterface
     */
    public static function getSelfCheckReportListV2Validate(array $params)
    {
        return self::getInstance()->validate(
            [
                "shopId",
                "startDate",
                "endDate",
                "sysTemplate",
                "pageSize",
                "pageNum",
                "state"
            ],
            $params,
            [
                "shopId"      => Rule::exists((new ShopModel())->getTable(), "id"),
                "startDate"   => [
                    "sometimes",
                    "string",
                    "date_format:Y-m-d"
                ],
                "endDate"     => [
                    "sometimes",
                    "string",
                    "date_format:Y-m-d"
                ],
                "sysTemplate" => [
                    "sometimes",
                    "int",
                    "in:" . implode(",", CruiseTemplateModel::TEMPLATE_TYPES[CruiseTemplateModel::TYPE_8])
                ],
                "pageSize"    => "required|int|min:1|max:100",
                "pageNum"     => "required|int|min:1",
                "state"       => [
                    "required",
                    "int",
                    "in:" . implode(",", [
                        CruiseOrderModel::STATUS_INIT,
                        CruiseOrderModel::STATUS_NOT_REVIEW,
                        CruiseOrderModel::STATUS_AUDIT_OK,
                        CruiseOrderModel::STATUS_AUDIT_ERROR,
                        CruiseOrderModel::STATUS_EXPIRED,
                    ])
                ]
            ]
        );
    }
}
